C# - Block Access To Files When Using The System.Web.Routing.UrlRoutingModule?
Jan 22, 2010
I'm using the System.Web.Routing.UrlRoutingModule.
With that I'm writing:
routes.Add(new Route(@"cart/add", new RouteHandler("~/Order/CartAdd.ashx")));
routes.Add(new Route(@"cart/delete", new RouteHandler("~/Order/CartDelete.ashx")));
And I also have one route called:
routes.Add(new Route(@"{*url}", new RouteHandler("~/Error/PageNotFound.ashx")));
But if I go directy to /Order/CartAdd.ashx I never enter the routing. It goes directly to that handler. And if I go to /Order/ I get a 403.14 error.
How do I instead catch those urls with the routing?
View 1 Replies
Similar Messages:
Mar 28, 2010
In ASP.net MVC 2, I can use routes.RouteExistingFiles = true; to send all requests through the routing system, even if they exist on the file system.
Usually, this ends up hitting the "{controller}/{action}/{id}" route and throws an exception as the controller cannot be found.
I do not want to use that route though (I have only a few URLs and they are specifically mapped), yet I would still like to prevent access to the file system.
Basically I want to Whitelist pages using IgnoreRoute. Is there a built-in way to do this?
My current approach is to still have a route "{*anything}" and generate a 404 when this is hit, but I'm just wondering if something is built-in already?
View 1 Replies
Dec 12, 2010
I am using:
ASP.NET 3.5 SP1 with Web Forms Routing thru Global.asax (System.Web.Routing and RegisterRoutes)IIS 7
Everything is working fine in my local machine, but it gives the following error in my hosting environment:
Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I did everything inside my web.config file mentioned in the following link:
[URL]
But I am still getting the above error.
What else am I supposed to do fix the error?
View 1 Replies
Apr 20, 2010
What i want to do is code in Global.asax file to check if current date is greater than EndDate(appsetting) it will block access to rest of the pages as what happens when using [Code]....
Moreover it will be a licencing system which will block the application after its EndDate that will be mentioned in web.config.
[Code]....
[Code]....
View 10 Replies
Oct 7, 2010
while doing debugging i found a blue dotted corner around catch block, while hovering it is showing system.exception...what does it mean and what to do
View 1 Replies
Jan 4, 2010
I create a custom http handler to block download of .wmv files e.g. www.pakdev.net/videos/file.wmv (blocked by httpHandler).
But the problem is that now silverlight cannot also stream these video files as they are blocked too.
View 1 Replies
Jan 4, 2010
On my website, www.pakdev.net, I create screencasts to which are streamed through silverlight.
I create a custom handler to block the download of .wmv files from the url like [URL]
But the problem is now the silverlight has also stopped streaming files.
View 1 Replies
Jan 22, 2010
I am implementing URL rewriting and this is not a MVC app, I am using .Net 3.5 Framework here is my simple setup: 1. My Link Page I have a link on my index.aspx page
(notice SEO friendly URL, purpose of Routing) --> <asp:HyperLink ID="HyperLink1" NavigateUrl="~/Category/Engine" runat="server">Engine</asp:HyperLink>
2. Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private static void RegisterRoutes()
{
System.Web.Routing.RouteTable.Routes.Add("category", new System.Web.Routing.Route("Category/{name}", new CategoryRouteHandler("~/catalog.aspx")));.........
View 5 Replies
Mar 29, 2011
How can I have my website block access to IE6? Redirecting it to a custom error page.
View 3 Replies
Jan 12, 2010
I am using System.Web.Routing with ASP.NET (3.5) Web Forms that will URL rewrite the following URL from
http://www.myurl.com/campaign/abc
http://www.myurl.com/default.aspx?campaign=abc
The code is as below:
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add("CampaignRoute", new Route
(
"{campaign_code}",
new CustomRouteHandler("~/default.aspx")
));
}
IRouteHandler implementation:
public class CustomRouteHandler : IRouteHandler
{
public CustomRouteHandler(string virtualPath)
{
VirtualPath = virtualPath;
}
public string VirtualPath { get; private set; }
public IHttpHandler GetHttpHandler(RequestContext
requestContext)
{
if (requestContext.RouteData.Values.ContainsKey("campaign_code"))
{
var code = requestContext.RouteData.Values["campaign_code"].ToString();
HttpContext.Current.RewritePath(
string.Concat(
VirtualPath,
"?campaign=" + code));
}
var page = BuildManager.CreateInstanceFromVirtualPath
(VirtualPath, typeof(Page)) as IHttpHandler;
return page;
}
However I noticed there are too many things to change on my existing aspx pages (i.e. links to javascript, links to css files).
So I am thinking if there's a way to keep above code but in the end rather than a rewrite just do a Request.Redirect or Server.Transfer to minimize the changes needed. So the purpose of using System.Web.Routing becomes solely for URL friendly on the first entry.How to ignore the rest of the patterns other than specificed in the code?
View 1 Replies
Jul 21, 2010
Is it possible to use the Microsoft (or Mono) supplied System.Web.Routing instead of the MonoRail routing stuff when building a Castle MonoRail app for ASP.NET?
View 1 Replies
Apr 20, 2010
anybody knows of blocking certain users (by IP) from accessing your website (website on asp.net mvc).
EDIT: I know that web-servers can do this as well, but I need this at the application level
View 3 Replies
Jan 7, 2010
I've sucefully runned it in my local server (Windows Server 2003 Standart) but after tried several times upload it to my hosting, it never works. The web hosting company told first that they didn't had System.Web.Routing.dll installed (but they said that they've .NET 3.5 installed..), then i've copied the dll to Bin folder and again with no sucess. Can someone give me a very basic example of and website using System.Web.Routing.dll so i can do the "final" test on webhost before i go to the company because they say that they have 3.5 installed but i'm starting to see that they didn't have? If possible, is there another way to test if this dll is installed in web hosting? (test all .dll running for example)
View 1 Replies
Feb 5, 2010
When I try to use Routes in new ASp.Net WebaPplication using .Net framowork 3.5
Line 7: Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Line 8: ' Code that runs on application startup Line 9: RegisterRoutes(RouteTable.Routes)
I encounter Error: Warning: BC40056: Namespace or type specified in the Imports 'System.Web.Routing' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Source Error: C:UsersTomAppDataLocalTempTemporary ASP.NET Fileswebsite2fec408f890149acApp_global.asax.2w_ytzx2.0.vb(26) : warning BC40056: Namespace or type specified in the Imports 'System.Web.Routing' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. Imports System.Web.Routing. I installed VS 2008 + sp1 on windows 7. and I am using Asp.net Developement server to Run Web Application.
View 2 Replies
Jan 27, 2010
I keep getting this error
'IgnoreRoute' is not a member of 'System.Web.Routing.RouteCollection'.
even though I have included the required namespace
system.web.mvc
system.web.routing
View 7 Replies
Aug 18, 2010
I need to setup a file handler to route with multiple sub directories something like tihs;
http://localhost/images/7/99/786936215595.jpg
I tried putting this in the global.asax file;
routes.Add(
"ImageRoute",
new Route("covers/{filepath}/{filename}",
new ImageRouteHandler()));
I am using the ImageHandler found in this Question, which works great if you have a single sub-directory (ie '/images/15/786936215595.jpg') but fails when you have multiple directories.
I tried setting up a wildcard and that didnt work (ie 'new Route("covers/{filepath}/*/{filename}"')
This is serving images from a large NAS (think something like 3 million images) so its not like I can just move files around.
View 2 Replies
May 7, 2010
I know a user can use the following code to access the content of web.config
string connectionString = ConfigurationManager.ConnectionStrings["MyConnect"].ConnectionString;
If I set EnvironmentPermission, can I block user to access the content of web.config?
View 1 Replies
Dec 22, 2010
I am using URL Routing in Asp.net 4. I have successfully got the url routing working, however i have encountered a problem with my web pages trying to access local files. For e.g. before i started using URL Routing, my web page was called [URL]. In this page i was making references to a CSS file and some Js files. They were referenced as follows : <link href="CSS/mycss.css" rel="stylesheet" type="text/css" /> and <script src="js/myjs.js" type="text/javascript"></script>. So basically i have two folders sitting on the route, called CSS and JS, containing the respective files.
However, after implementing routing my url has now become e.g. [URL] This is fine, but what has now happened is that my CSS and JS have become inaccessible as they are now referenced as follows: [url] or [url] i know i can sort of resolve this by referencing my files as follows
<link href="../../../CSS/mycss.css" rel="stylesheet" type="text/css" />
and <script src="../../../js/myjs.js" type="text/javascript"></script>.
But that means i have to change the path for every reference, and i have too many. Then also i must change the references to any background images for instance in my css to have the same path. This is a huge nuisance, and pain in the back side. Does anybody know of a solution for this, where i will not need to change the referencing for the files.
View 6 Replies
Feb 21, 2011
I am testing with an MVC 2 project generated by the template in VS 2010. I have simply added an ADO.NET Entity Data Model, as well as a WCF Data Service that leverages the data model.
I was able to access the web application content (views, as well as the data served by the data service) just fine until the day before yesterday.
Yesterday I decided to reinstall Windows 7 on my development laptop, and I chose to go with the release of the OS with SP1. Of course, I reinstalled Visual Studio as well.
Now the same project gives me HTTP 404 errors when I try to browse to the data url .../MyTodoDataService.svc).
Here are some interesting facts:
The same data service works just fine in a Web Forms application. I see the problem only when deploying to the Local IIS Web Server (Cassini runs it just fine).
I am able to browse to the data url if force MVC routing to ignore the appropriate route by calling "IgnoreRoute" on the RouteCollection in Global.asax.
View 7 Replies
Jun 4, 2010
I am making use of 3-Tier architecture while making my project. And in Data Access Layer I am making use of application block, but application gets a connection string from web.config; but ClassLibrary of Data Access Layer doesn't contain web config file. How can I access connection string from Data Access layer?
View 5 Replies
Aug 14, 2010
I have a problem in my asp application. In my application I have an own authentication mechanism so in the web.config file I have <authentication mode="None"/>
Inside the application users can upload files to the folder I've created (App_Files). I would like to give access to the folder only once they are logged in (Session["Login"] is no null).
I dont want not logged in users to be able to access the files over a url address in the browser (like http://<server>/App_Files/Filename.pdf)
View 7 Replies
Mar 30, 2011
I am using IIS7's URLRewrite feature to hide the .aspx extension in my ASP.NET WebForms application's URLs.
I'm using the following configuration:
[code]....
I can now browse to:
[URL]
and this is rewritten to:
[URL]
This preserves the "pretty" url in the browser address bar. I have also updated all my links on the site to use the extensionless URLs.
The problem is that the underlying .aspx pages can still be accessed directly and I'd like to prevent this.
If a user browses to [URL] I'd like it to either redirect/rewrite to [URL], or at the very least just return a "Page not found".
Update:
I managed to get this working by redirecting all .aspx pages to the home directory. This isn't ideal as I'd prefer to send them to the non-.aspx version, but it will do for now.
<rule name="Block .aspx" stopProcessing="true">
<match url=".aspx" />
<action type="Redirect" url="/" />
</rule>`
How do I rewrite and redirect URLs that directly address .aspx pages to my friendly URL format?
View 2 Replies
Feb 9, 2011
my page is very simple, one gridviews and one ObjectDataSource.here's my code :
<%@ Page Title="" Language="C#" MasterPageFile="~/site.Master" AutoEventWireup="true"
CodeBehind="default.aspx.cs" Inherits="cHospital._default" %>
[code]...
I also posted my question on another web site, one suggestion I got is move my codes to codebehind
(http://entlib.codeplex.com/Thread/View.aspx?ThreadId=245208)
But this is ObjectDataSources, my understanding is everything have to stay in Class file.
View 1 Replies
Jun 24, 2010
I am using URL routing in asp.net application (not MVC) . I have Admin folder in my aaplication which has admin related aspx pages with seperate web.config. I have seperate login form for admin users which is placed in admin folder itself. My issue is whenever I hit [URL] (which I want to go to login form for admin)- it tries to authenticate and goes to login url mentioned in web.config of root folder.
Note: Admin folder has anonymous access in root config file. Also I have set default document in config of Admin folder. I have added following line in global.asax so that routing doesnt work for files in admin folder;
routes.Add(new
Route("admin/{*resource}",
new
StopRoutingHandler()));
I am really confused what is the issue? What I am missing?
View 6 Replies
Dec 4, 2010
i need to copy or move files from one system to another system.
i did this but it saying invalid path..
[code]....
View 1 Replies