URL Rewriting in ASP.NET 4.0 [duplicate] - c#

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ASP.NET 4.0 URL Rewriting: How to deal with the IDs
I am trying to do url re-writing in my asp.net c# project, and I searched internet but did not get what I was looking for.
Say, for example I have following url:
http://www.example.com/Question.aspx?qid=1
Now, Question.aspx finds a question against (which has title and body field) for qid from the db and displays it. I want to display question title in url.
My requirement is something like this:
http://www.example.com/Question/1/QuestionTitleGoesHere
Can anyone please suggest that how can I achieve this ASP.NET 4.0?

You can check following working examples of URL Rewriting in asp.net web forms projects using
URL Rewriting using ASP.NET for SEO
Tip/Trick: Url Rewriting with ASP.NET

In IIS you can use Url Rewrite to achieve this.
If you need this to be within the application, could you look at using MVC3/MVC4 instead of webforms? If that is an option.

I think you should try these links:
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
ASP.NET Routing
They will help you.

Related

System.Web.Mvc.HttpPostAttribute vs System.Web.Http.HttpPostAttribute? [duplicate]

This question already has answers here:
What is the different between System.Web.Http.HttpPut Vs System.Web.Mvc.HttpPut
(2 answers)
Closed 3 years ago.
In my Web API project which is based on the ASP.NET MVC, I want to use the HttpPost attribute. When I've added that onto the action, The IntelliSense suggests me these two namespaces:
System.Web.Mvc.HttpPostAttribute
System.Web.Http.HttpPostAttribute
Which one should be used and why?
Prior to ASP.NET Core, MVC and WebAPI were mainly separate libraries.
The .Mvc namespace applies to MVC controllers, the .Http namespace to Web API controllers.

Asp and WebClient: How to get dynamically actual host? [duplicate]

This question already has answers here:
How to get "Host:" header from HttpContext (asp.net)
(4 answers)
Closed 8 years ago.
I want to get datas from an html file on my asp webserver, in Javascript to get actual host we can use the following:
~/mydatas.php
It gives on localhost: "http://localhost/mydatas.php"
I want the same thing but in C# can you help me?
Thanks you.
You could also search in stackoverflow and you will find a lot of answered question which had the same problematic than you. Like this one
Hopes it will help you !
Edit : You can use
HttpContext.Current.Request.Url.AbsoluteUri
It will give you the URL of your web page.
I've already try
HttpContext.Current.Request.Url.Host
which gives on localhost
:\windows\system32\inetsrv\localhost
...

How to check from which action I came in asp.net mvc [duplicate]

This question already has answers here:
How do I get the referrer URL in an ASP.NET MVC action?
(4 answers)
Closed 8 years ago.
I have asp.net mvc 4 application, where I need to do some action when I came from HomeController ActionResult DoSmth(). How can I check this?
I use
Request.UrlRefferer
To do this.
You can use the following
var controller = (string)this.RouteData.Values["controller"];
var action = (string)this.RouteData.Values["action"];
Not sure if relevant, but if you want to make sure that action is rendered only from your code you can use attribute [ChildActtion].
Otherwise check this answer: ASP.NET MVC - Check if request comes from another action

URLs like on a visualstudio.com - advanced routing? [duplicate]

This question already has answers here:
Is it possible to make an ASP.NET MVC route based on a subdomain?
(10 answers)
Closed 8 years ago.
I'm writing here becouse one question doesn't let me sleep calmly. How it's possible that site www.visualstudio.com when I sign in to free TFS account, create special 'part' of site with url {myprojectname}.visualstudio.com?. Is it achieveable in my project using ASP.NET MVC 4 or 5? How it doesn't affect in current DNS system? or it affect? What should I read to let my site be so deeply customizable?
for example:
user1.mysite.xx
user2.mysite.xx/aaa/4/sda/something_other
The easiest way is to define a wildcard DNS A or CNAME entry like (BIND syntax):
*.myside.xx. IN A x.x.x.x
In Windows you can use the command line dns tool for it: http://support.microsoft.com/default.aspx?scid=kb;en-us;840687
After that regardless what you write as username.myside.xx it will hit your webserver. From your code you can decide what to do, make a redirect to username.myside.com/username or whatever else

How to prevent Cross site scripting XSS using MVC 3 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you avoid XSS vulnerabilities in ASP.Net (MVC)?
Hi I need to create a guest book, where users can add their comments and have theme being displayed without moderation on a page.
I'm using Asp.Net MVC 3 in C#.
Could you point me out some tecnics? thanks
Thanks for your time.
PS I'm using Razor
Just make sure all user generated content is HTML encoded before you write it to the browser and you'll be fine. Razor view engine does this by default... it's actually quite hard to screw up on this using Razor.
So:
#"<script>badness</script>"
in Razor would render in HTML as
<script>badness%lt;/script>
to achieve the same in ASP.NET view engine use <%:expression%> as opposed to <%=expression%>
<%:"<script>badness</script>"%>
You could you the AntiXSS library. This is mentioned by:
http://weblogs.asp.net/jgalloway/archive/2011/04/28/using-antixss-4-1-beta-as-the-default-encoder-in-asp-net.aspx
http://haacked.com/archive/2010/04/06/using-antixss-as-the-default-encoder-for-asp-net.aspx

Categories