Cannot load image from virtual directory in iis

We are using ServiceStack as our API service.
And the service includes Virtual Directory in IIS.

If we just try to access to path of service, it works fine.
The problem is occured when we try to get the image from virtual path.

/LocalFolderOfService/image.jpg -> Working
/VirtualDirectoryOfIIS/image.jpg -> Not working

Without registering servicestack handler, we can see that image well.

<handlers>
  <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>

Could you guide us what is the problem you expected?

Please put together a small stand-alone project that shows the issue on GitHub and add a link to the project here.

I just tested by using default your empty apt.net project.
Now I got an error text as 404 with 404 httpresponse code.

Do I need to set specific configuration to use vdir?

Please link to the exact project you used and any configuration that you used.

I commit my test code to bolow github.

This project doesn’t contain a repro, it just looks like an empty project without any image or home page and with the ServiceStack configuration in Web.config commented out.

After uncommenting the configuration in Web.config and creating the default virtual directory, I’ve added a basic default.html in the ServiceStackTest web host project:

<!DOCTYPE html>
<html>
<body>
    <h1>Home Page</h1>
    <img src="image.png">
</body>
</html>

With an image.png in the same directory and it renders as expected:

With the image returned in the expected:

http://localhost/ServiceStackTest/image.png

OMG, I think we are talking differnet things each other.
I have a problem when I tried to acces the image through VDIR of IIS.

Of course your guide, it works. (I told you, in above)

The problem is occured when we try to get the image from virtual directory of IIS.
/local-dir/image.jpg -> Working
/v-dir/image.jpg -> Not working (404 error)

Then I really don’t know what you’re saying doesn’t work, because the URL shows the request from an IIS Virtual Directory.

I’ve renamed the IIS Virtual Directory so it’s different to the physical directory so you can see the request is from the IIS Virtual Directory not the physical local directory:

What’s important is that I’m able to identify what the issue is and be able to reproduce it.

Please include the full HTTP Request/Response Headers of the 404 and a screenshot of your IIS virtual directory.

Those 2 directories are set same location.


This isn’t likely a supported ServiceStack scenario, why aren’t you hosting your project from the Virtual Directory created in VS.NET?

I’ll see if there’s a way it can be configured to work, which URL brings up the metadata page?

http://localhost:8444/metadata
http://localhost:8444/vdir/metadata

Can you also enable DebugMode and paste the JSON response from:

http://localhost:8444/vdir/?debug=requestinfo

Thank you for your support.

In fact, we are using shared repository to sync multiple servers.
That is the reason why we made vdir to share assets (jpg, png…).
And the vdir linked with network drive.

API is need not to provide from virtual path.
I just want to know why I faced 404 error when I use vdir in IIS.

It seems that your handler catched my request. And I found if I added prefix, like below, now I can see the images.

<handlers>
	<add path="api*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>

And I attached debug log.

{
"Usage": "append '?debug=requestinfo' to any querystring. Optional params: virtualPathCount",
"Host": "_v5.50_ServiceStackTest",
"HostType": "ASP.NET (AppHostBase)",
"StartedAt": "2019-06-03 11:18:46",
"Date": "2019-06-03 11:24:32",
"ServiceName": "ServiceStackTest",
"UserHostAddress": "::1",
"HttpMethod": "GET",
"PathInfo": "/vdir/1.png",
"OriginalPathInfo": "/vdir/1.png",
"StripApplicationVirtualPath": false,
"GetLeftPath": "http://localhost:8444",
"Path": "/vdir/1.png",
"GetPathUrl": "http://localhost:8444/vdir/1.png",
"AbsoluteUri": "http://localhost:8444/vdir/1.png?debug=requestinfo",
"ApplicationBaseUrl": "http://localhost:8444",
"ResolveAbsoluteUrl": "http://localhost:8444/resolve",
"ApplicationPath": "/",
"ApplicationVirtualPath": "/",
"VirtualAbsolutePathRoot": "/",
"VirtualAppRelativePathRoot": "~/",
"RootDirectoryPath": "D:\\WorkSpace\\ToDo\\TestCode\\ServiceStackTest\\ServiceStackTest\\ServiceStackTest\\bin\\Release\\Publish",
"ContentRootDirectoryPath": "D:\\WorkSpace\\ToDo\\TestCode\\ServiceStackTest\\ServiceStackTest\\ServiceStackTest\\bin\\Release\\Publish",
"CurrentDirectory": "c:\\windows\\system32\\inetsrv",
"HandlerFactoryArgs": "GET|/vdir/1.png|D:\\WorkSpace\\ToDo\\TestCode\\ServiceStackTest\\ServiceStackTest\\ServiceStackTest\\bin\\Release\\Publish\\localdir\\1.png",
"RawUrl": "/vdir/1.png?debug=requestinfo",
"ContentType": "",
"Status": 0,
"ContentLength": 0,
"Headers": {
	"Connection": "keep-alive",
	"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
	"Accept-Encoding": "gzip, deflate, br",
	"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7,id;q=0.6",
	"Cookie": "utag_main=v_id:0166e2df1cb30001e53a0e0999f703072002406a00bd0$_sn:1$_ss:0$_st:1541406500475$ses_id:1541404564660%3Bexp-session$_pn:2%3Bexp-session; _ga=GA1.1.1508900839.1541404701; Abp.Localization.CultureName=en; Culture=en-US; remember-waorgid=waroot; remember-loginid=sysadmin; WAU={\"UserSeq\":1,\"OrgSeq\":1,\"LoginID\":\"sysadmin\",\"Password\":\"\",\"PasswordChangeUTC\":\"\\/Date(-62135596800000)\\/\",\"PassPattern\":\"\",\"UserNickName\":\"sysadmin\",\"UserTypeEnum\":\"BOS\",\"Email\":\"sysadmin@wa.co.kr\",\"CellPhoneNo\":\"\",\"Description\":\"\",\"UserStatusEnum\":\"Active\",\"LoginFailcount\":52,\"LastLoginFailDateTimeUTC\":\"\\/Date(1559515990070)\\/\",\"LoginIDCreated\":\"sysadmin\",\"DateCreatedUTC\":\"\\/Date(1440978540000)\\/\",\"LoginIDModified\":\"sysadmin\",\"DateModifiedUTC\":\"\\/Date(1448915575300)\\/\",\"OrgTypeEnum\":\"WAROOT\",\"OrgStatusEnum\":\"Active\",\"WAOrgID\":\"WAROOT\",\"WAOrgName\":\"WA\",\"EmployeeSeq\":0,\"OrgKeys\":null,\"LanguageCodeEnumStr\":\"\",\"LocaleFormatEnum\":\"\",\"TimeZoneOffset\":\"\",\"DSTFromUTC\":\"\\/Date(-2209021200000)\\/\",\"DSTToUTC\":\"\\/Date(-2209021200000)\\/\",\"UserGroupSeqList\":null}; UPDATE=2019-06-03 오후 6:45:28; .WA_AUTH=260706E233059F0B3071CFA0376EA5504E4BE508B741206F907C022D94AB7411ADE9B047E9F0CBC7CCB81714D01EB8D32D8AB41FC123100B3C9607A21031BD9F842F1B4ABC86CDD70B8ED0B228B8C1D643CF6A3E43C6A88AD9FB82ACE08C37D155E7BCC786046BCDDE8D4439393741A9CD1372F4AF81A1301FF699D31F470828E4EB6783B5446747BC249BACA6A64BFFE6501624700BC9B0197E77227E2A5A4AA108C663243B8EFE3E6CA8A600D931C2A2ABCBD2DAB0771C9FEBBF7B0C53E363D64F55F4FE84BB40B0B49824029908A3071917EBE3C7F4312E1747621EC6BEAD9FC5FF5121F641D13FB11E6FC65EBDB0FE8A7F542049A0D57D3C4A23A3E6EBEF1CE132B7FBACBC11E593740ECF0786AC96A7CFD91CC114EF21E9DBA326C3E556E0D8BF080A3D9F0DCE614DACB3350FB92218F762D508466A51C50BA5DB8D27C4665836313A37FA3A59FD4729C1BB38FEAF308F95EEFCD773F64B27AFEEDFE946512EA59B9222336A7D1E75C55EA73666BB464A917ED27AA969C552200FCD59643BF5DFEFC1A55B715870D1FCE36E46B42EBF26FA460D2D28A66379F7A7F85F3288C981E01F0C3CF3905A4D265E4446E0AABC7B4580056AC862EF24A1886816E0A93E72570C11DC9BF3160B9B73437160598151D130ED22E2C25A078B27EDF597D3660BE25490819B2E863E0FA537956B20024B728CDBA1C2CB4B346A93569A95FA04A7C21DCE0A3512895C6E2F4A9540163ACF3F5D5C26F2A0FA873D396ED99CCE49145EFAA35F2A5732A2ACD228CC71F0421E86EC928B5A71419AEBD7C84916D751E40F037110C3ADE96775DF5D95C19981A19A2031DD95006F9C0DA1C567263033FE6A47F09659F931C28DF3D16DAB1777E1744C6866DB0E27BA6385722CFEA1BB360B2CA385F63F1802492E432DAC0B01198ECD1EC239341EE6FFC7A164070A7AAE0FBF068D7649BAD2FE37EE4DF76F55BABC76346388F32156911E17ADC8D54582023D032B9D7813FE7E29957F35CCD8ACF613F7764E98E48963E1C1A4FF7A94C8500ECCA316EDB302D9E557DCBE0893A7B2A3841431FF98AAF9713AE6AA006161FC24A3D459E760BDE5E709B76380941E0A471C461EC04214C44C1AACA9A14F4FCDE5406CB50BE3A69E76A3A7548FE0C40016E45D73EDC9AF781B1EAEB091272436379D6DAF9A6B6CBB3DEB1DF1B3E13CE5D90B1C23FA8DA2DC2892A65ACA96DDBA36F9CA702A550ED8D5E3A4555BC5EC0C0DEE2915789C6CB774C15B005456EDA6405A984BE492928FD0655E9E04CE0C8542B55E0BA13B567DE233E53BA979B4C3EA2920F49E780B94E788EB3F3660FD9E6A338753A0761ABEADFEA51030895AB2762D218F486CE6F7016DB7E951658497AB4797F8E4A07F083A2F8EB294ED6869FEB35D22910918F2AD6C5F36ECC0026CA8EF4F6C6F17D4B86A83713429B18AC8110338D1C2DA2249233F94BBB4D5B8A117185AE71B3B7CB79C050AF16DEBE4F1AE854CA06D3B3C5812B8079688E72D0862A095A940FF860D6363AF5F7ED0FC9B98A54C186DC263EBD613FCBB4CC7E668A6E14C7EA1D1CFDA24B80A4FB6D89CD63CB5205622E6CBEA87CF57AB5873548E8AE28E301F40AC4FEAB25810ECFEADE053B133D641C0D7CD54AFD8D97322DDBC510FA514B1BC00C5299315C3E7DD4793F1CC1C5351EC6935FAEFEE844B1A23BEA7DDA2A6D36E079827B675642A86EEDF6B2845B602430B4F1EEC4CCC256A26FBB795AD7FB8CB9D336F67E6A7A4BFF823519B928213AFF9956372FF331F47CCAE8CD0A6032CFEB2A938CDA771",
	"Host": "localhost:8444",
	"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
	"Upgrade-Insecure-Requests": "1"
},
"QueryString": {
	"debug": "requestinfo"
},
"FormData": {
	
},
"AcceptTypes": ["text/html",
"application/xhtml+xml",
"application/xml;q=0.9",
"image/webp",
"image/apng",
"*/*;q=0.8",
"application/signed-exchange;v=b3"],
"OperationName": "/vdir/1.png",
"ResponseContentType": "text/html",
"RequestAttributes": "Localhost, InSecure, HttpGet",
"Ipv4Addresses": "169.254.109.95/255.255.0.0, 192.168.100.178/255.255.255.0, 169.254.123.178/255.255.0.0, 169.254.166.38/255.255.0.0, 169.254.130.98/255.255.0.0, 169.254.117.102/255.255.0.0, 169.254.178.133/255.255.0.0, 127.0.0.1/255.0.0.0, 172.25.38.113/255.255.255.240",
"Ipv6Addresses": "fe80::94d2:7626:7dd9:6d5f, fe80::c8dc:fad2:3d84:c4b8, fe80::4865:4088:282c:7bb2, fe80::850c:3c4e:3538:a626, fe80::f5ac:42b5:f2ac:8262, fe80::1579:34a6:abac:7566, fe80::edc3:e051:531a:b285, ::1, fe80::fd48:2fc2:72fa:c20c",
"LogonUserInfo": {
	"Name": "NT AUTHORITY\\IUSR",
	"AuthenticationType": "",
	"IsAuthenticated": "False",
	"IsAnonymous": "False",
	"IsGuest": "False",
	"IsSystem": "False",
	"Groups": "S-1-1-0, S-1-5-32-545, S-1-2-1, S-1-5-11, S-1-5-15, S-1-2-0",
	"User": "S-1-5-17",
	"User.AccountDomainSid": "null",
	"User.IsAccountSid": "False"
},
"DebugString": "System.Web.HttpRequest|System.Web.HttpResponse",
"PluginsLoaded": ["HtmlFormat",
"CsvFormat",
"PredefinedRoutesFeature",
"MetadataFeature",
"NativeTypesFeature",
"HttpCacheFeature",
"RequestInfoFeature",
"SpanFormats"],
"StartUpErrors": [],
"AsyncErrors": [],
"LastRequestInfo": {
	"HandlerType": "RequestInfoHandler",
	"OperationName": "RequestInfoHandler",
	"PathInfo": ""
},
"Stats": {
	"RawHttpHandlers": "2",
	"PreRequestFilters": "0",
	"RequestBinders": "0",
	"GlobalRequestFilters": "0",
	"GlobalRequestFiltersAsync": "0",
	"GlobalResponseFilters": "1",
	"GlobalResponseFiltersAsync": "1",
	"CatchAllHandlers": "3",
	"Plugins": "8",
	"ViewEngines": "0",
	"RequestTypes": "12",
	"ResponseTypes": "3",
	"ServiceTypes": "2",
	"RestPaths": "12",
	"ContentTypes": "6",
	"EnableFeatures": "All",
	"VirtualPathProvider": "[MemoryVirtualFiles: /], [FileSystemVirtualFiles: D:\\WorkSpace\\ToDo\\TestCode\\ServiceStackTest\\ServiceStackTest\\ServiceStackTest\\bin\\Release\\Publish], [ResourceVirtualFiles: ServiceStackTest], [ResourceVirtualFiles: ServiceStack]"
},
"VirtualPathProviderFiles": []
}

Because when ServiceStack is registered at the default path it handles all requests but in this case you need IIS to handle this request.

Right, you would need to configure ServiceStack at a different path to have Requests outside the path not handled by ServiceStack.

If you just want to share the same folder resources an alternative to using a IIS Virtual Directory is to register a File System Mapping which will let you have ServiceStack hosted at the root path and avoid any custom IIS settings for your Application.