I have a directory which hosts my web services based on ServiceStack. Inside the directory I have a help folder which has some html pages in it. However when I try browse to those pages, ServiceStack thinks that I am trying to hit a route and gives me "Handler for Request not found".
Is there any way to tell ServiceStack to ignore certain routes? If a route matches a directory present in IIS surely it can't be a service route?
http://www.example.com/exampleservice/metadata <-- fine
http://www.example.com/exampleservice/help/main.html <-- has nothing to do with ServiceStack as it's a directory
This looks to have been nicely implemented in ServiceStack v4. Demis posted about it here.
The Virtual FileSystem is now fully integrated into the rest of ServiceStack, this enables a few interesting things:
The Config.WebHostPhysicalPath sets where you want physical files in ServiceStack to be serve from
You can now access static files when ServiceStack is mounted at a custom path, e.g. /api/default.html will serve the static file at ~/default.html
By Default, ServiceStack falls back (i.e when no physical file exists) to looking for Embedded Resource Files inside dlls.
You can specify the number and precedence of which Assemblies it looks at with Config.EmbeddedResourceSources which by default looks at:
The assembly that contains your AppHost
ServiceStack.dll
Related
Background: The division I work at within my company has a company intranet webpage with quick links to files and directories located on our local server, and within a shared drive from another server at a different location within the company. The users have the shared drive mapped on their machine using their credentials, and then they can use the home web page to quickly navigate to common files or directories. This worked fine for many years with IE, but it does not in Edge or other common browsers due to a security violation: "Not allowed to load local resource: " Now that IE's support is ending soon we want to get the links working in Edge to use.
Our ASP.NET Core application runs within IIS, and on our local server. Alternatively, I can use an action method instead of the absolute path to a file on the local server since the application is hosted on it. I do this by using the drive letter and full path to the file to read into a byte array and return as a File. I do not know how to do this for the shared server, where users can download files and open up a folder within the browser.
Currently we have static links to a file like: File
or Directory: Directory
I can copy the absolute path into any browser: file://///shared-server-name/Folder and it will show me the folder and its contents. I just can't do it through the HTML markup outside of IE.
What I've tried so far:
Instead of the static links, I tried redirecting to the absolute path using an action method in the controller:
public ActionResult GetFile()
{
redirect("shared-server-name/Folder")
}
This returns an error in the browser: "It looks like the webpage at https://localhost:*****/home/getfile might be having issues, or it may have moved permanently to a new web address."
I tried doing impersonation to see if it was because of the app identity the application was using:
IPrincipal p = _httpContextAccessor.HttpContext.User;
if (p.Identity is WindowsIdentity wid)
{
await WindowsIdentity.RunImpersonated(wid.AccessToken, () => {
bool exists= Exists("shared-server-name/Folder");
log.Debug(exists);
return Task.CompletedTask;
});
}
returns false for exists.
I understand the reason for the security error, but because this is an intranet site, and the access to the shared drive is only through users who are provisioned to it, we'd like to keep the same setup within Edge going forward.
From this blog written by EricLaw (Edge PM), we can know that
For security reasons, Microsoft Edge 76+ and Chrome impose a number of restrictions on file:// URLs, including forbidding navigation to file:// URLs from non-file:// URLs.
The behavior is by design in Edge and there's no option to disable this navigation blocking in Edge. The only thing you can do is using one of the three workarounds listed in the blog:
Open the website in IE mode.
Use extensions like Enable local file links.
Enable group policy IntranetFileLinksEnabled for Edge 95+.
For the group policy, please note that https://localhost/ is considered internet zone by default and can't be configured by the policy.
I have a "Tools" area of the MVC3 site I'm currently working on. One of the tools I'm integrating on the site I need to run in a virtual directory. Setting up a virtual directory under the /Tools folder works fine for the app itself, but for navigation to /Tools/, I'm getting "Directory listing not allowed". How do I tell IIS to let MVC routes handle this URL?
We'll be using IIS6 in production, so it's important for it to work with that.
Thanks in advance.
EDIT: For clarity, here's the setup:
/Tools/RoutedTool1
/Tools/ToolInVirtualDirectory
/Tools/RoutedTool2
/Tools/
The routes for the routed tools work fine, but since I had to create a directory under the root to setup the "ToolInVirtualDirectory", IIS is hijacking the "/Tools/" request and trying to send it to the directory, ignoring the route.
You should set routes.RouteExistingFiles = true in Global.asax.cs.
Remember that since this property plays at global level you have to ignore the css files and other stuff you don't need to handle by the routing infrstructure before setting this. For more idea please refer this post.
In your RegisterRoutes section in Global.asax, you add ignore routes that the routing system ignores. There should already be an example for .axd's in the config.
I have a ASP.NET application. Inside the asp.net application I have a folder called WebServices where I keep all the .asmx files.
I am referring these asmx files inside asp.net .cs files. Instead of giving the full url to the webservice.url property how can i set the path like this.
ds.Url = this.ResolveUrl("~/WebServices/xxx.asmx");
Is HttpServerUtility.MapPath what you're looking for?
ds.Url = Server.MapPath("~/WebServices/xxx.asmx");
You can get hold of it either via Server property in Page class, or via HttpContext.Current.Server chain.
Even better, I'd store this URL in an application configuration file.
Your questions suggests that you have your webservices in the same project as the consuming apllication. This will not work. Move all your webservices into a seperate project.
If your services and cs files both are in same project then you donot need to set the URL as such. These services can be called as if you can call other classes in your application.
I have a ASP .NET load balanced application (webservice and website). It runs on SQL server. I need to be able to provide large files for download. However, because of the load balancing situation, the files are stored in the SQL database as opposed to the file system. BITS seems to be the best approach. I have full control of the client. However, i don't know how to configure BITS to read the file from the database. I know how to write the C# code for that, but i don't know how to get BITS to hook into it as opposed to reading the file from the file system.
Any ideas?
You can create a custom http handler by implementing System.Web.IHttpHandler. The ProcessRequest(HttpContext context) method is where you will write your file retrieval code from the database. Since BITS operates with range requests you will need to parse the value of context.Request.Headers["Range"] to get the start and end bytes requested. In the ProcessRequest you can read the binary from the database using the SqlCommand.ExecuteReader(CommandBehavior.SequentialAccess) method and set the resulting binary in context.Response.OutputStream. Remember to call context.Response.Flush() at the end.
The custom HttpHandler will serve a particular file extension (e.g. '.file'). This is what needs to be done in IIS:
Both IIS Versions
Add to section in in web.config:
IIS 6.0
Add .file (application/x-zip-compressed) extension as MIME type for the website.
Add Application Extension (Website Properties Virtual Directory Configuration Mappings)
Extension: .file
Executable Path(s): %windir%\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
IIS 7.0
Add to section in in web.config:
Add to section in in web.config:
<mimeMap fileExtension=".file" mimeType="application/x-zip-compressed" />
Hope that's enough to get you started.
Have a look at 2008 Books Online OpenSqlFilestream. That API has examples that may help you.
Background
I have a PDF file located (under my Project) in an Assets > Documents folder:
When my application gets deployed, it gets deployed to a particular folder on the domain. For example, http://www.domain.com/MyAppFolder. I want to be able to access this PDF file by linking to http://www.domain.com/MyAppFolder/Assets/Documents/EZTrac_UserGuide_NewSys.pdf
Problem
I can't seem to get the routing correct for this, as it keeps trying to route this request to a controller. Here is the modification I made to the routing:
routes.IgnoreRoute("MyAppFolder/Assets/Documents/EZTrac_UserGuide_NewSys.pdf");
But this is the result that I get:
The IControllerFactory
'EZTrac.DependencyResolution.ControllerFactory'
did not return a controller for a
controller named 'Assets'.
Try removing the MyAppFolder from your routes.
routes.IgnoreRoute("Assets/Documents/EZTrac_UserGuide_NewSys.pdf");