I am working on one application it's like twitter.
So how can I accomplish the url such as,
twitter.com/username
This will open profile related to username.
I am creating using asp.net.
Thank you
If you are planning on using MVC Razor, it will be as simple as passing a query string parameter to your page. For example:
public ActionResult Index(string name)
{
//Get user information and pass to view
User userDetails = SomeLogic.GetUser(name);
return View(userDetails);
}
Or, if using ASP.NET Web Forms you will have to use Friendly URL's by adding a Nuget package. Tutorial can be found here: http://blogs.technet.com/b/southasiamvp/archive/2014/03/31/guest-post-exploring-asp-net-friendlyurls.aspx
In the grand scheme of things, all you need to do is pass a query string parameter to your page. Using the friendly URL's will help you accomplish the URL format you require.
Update
From your comment, I see you are using Web Forms, so I will modify the answer on getting a query string value. The code below won't render URL in a friendly format, but I am hoping you will then be able to modify the example based on the link I provided above.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["name"] != null && !String.IsNullOrEmpty(Request.QueryString["name"].ToString())
{
string myNameValue = Request.QueryString["name"].ToString();
//Since you have the name in the querystring, pass value to method that retrieves the record
User userDetails = SomeLogic.GetUser(name);
}
}
So the URL will be: profile.com/profile.aspx?name=John.
But as I stated, you will need to modify the code to change the example to use Friendly URL's, that can be found in this tutorial: http://blogs.technet.com/b/southasiamvp/archive/2014/03/31/guest-post-exploring-asp-net-friendlyurls.aspx
Related
I am writing an e-commerce website using DotNetNuke, and I have ran into a problem. For example I have a module on a page that has a URL of mydomain/productType/product-pages. What I would like is to pass a query string to this page with the item number of product (lets say its name is bacon). And when page loads, I would like both the breadcrumbs and URL(at browser) to read mydomain/productType/product-pages/bacon. I have researched how to change the page title, meta description, and all that already and have tested and it works - but just cannot find a way to modify the URL. I don't even know if this is possible. My goal is to not create all the pages for products within DNN, because this will change over time. I'm pretty sure I can create a page within DNN each time page is passed the query string which is a possibility, and another possibility would be have my other module create the link like it should read(just no page created) and DNN would just land on product-pages just add the /bacon? But I would rather just spoof the URL if possible.
Any suggestions or help would be greatly appreciated, and Thanks for reading.
Below is code snippet for changing the title and description:
protected void Page_PreRender(object sender, EventArgs e)
{
string pageName = Request.QueryString["pageName"];
if (!string.IsNullOrEmpty(pageName))
{
Page.Title = pageName;
Page.MetaDescription = "Blah";
Page.MetaKeywords = "Stuff,more stuff";
var url = HttpContext.Current.Request.RawUrl;
//Page.ResolveUrl(url + "/" + pageName);//this didnt work
//below is another way compared to top
//DotNetNuke.Framework.CDefault myPage = new
DotNetNuke.Framework.CDefault();
//myPage = (CDefault)this.Page;
//myPage.Title = "This is the new title";
}
}
The best way to manipulate the URLs for your custom module is by building a Extension URL provider. But you need to reverse your thinking about the problem. You don't want an ugly URL with a querystring argument to change into another URL. Rather, you start with the desired URL path and you want that to resolve or be "written" as the ugly querystring URL under the covers. That's what a Extension URL provider does.
I have a tutorial on DNNHero.com that walks you through it.
https://www.dnnhero.com/video/introduction-and-url-rewriting-basics
Unfortunately, that video is behind a paywall. (IMHO, it is worth the cost even for this one tutorial and code.)
You can also check out the blog:
https://www.dnnsoftware.com/wiki/extension-url-providers#:~:text=An%20Extension%20URL%20Provider%20is,and%20logic%20to%20be%20implemented.
We are using an application that runs on asp.net and C#. When a user is logged in, their profile information is displayed (name, id number) on a Profile page (information comes from MSSQL). I would like to get the id number for the logged in user and pass that value to an embedded form (this part I know I can do), the struggle is figuring out how to get the id number from one page to the other page.
I am not proficient with C# or asp.net but I did find where the id value is at, I am not sure how to call it from my form page?
Pass Values Between ASP.NET Web Forms Pages
The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web Forms page:
Use a query string
Get HTTP POST information from the source page
The following options are available only when the source and target pages are in the same ASP.NET Web application:
Use session state
Create public properties in the source page and access the property
values in the target page
Get control information in the target page from controls in the
source page
The main factor that should influence your approach should be the fact that this is a secure application and you do not want the information being passed to be prone to scrutiny.
First Option:
Use Cookies
On your firstPage.aspx
HttpCookie appCookie = new HttpCookie("IdValue");
appCookie.Value = "The value of your id here" or id.ToString();
appCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(appCookie);
To get:
SecondPage.aspx
HttpCookie aCookie = Request.Cookies["IdValue"];
String getValue = aCookie.Value.ToString();
Cookies expires depends on your Settings here appCookie.Expires = DateTime.Now.AddDays(1); it can be AddDays('MoreNumberofdays') like AddDays(4) it will expires in 4 days. Something like that.
some additional Guide
Second Option:
Class:
public class Class1
{
public static string storevalue;
}
Page1.aspx
protected void Page_Load(object sender, EventArgs e)
{
Class1.storevalue = "This is the value from page1";
Response.Redirect("WebForm2.aspx");
}
Page2.aspx
protected void Page_Load(object sender, EventArgs e)
{
string getvalue = Class1.storevalue;
}
I have to following problem:
When I go to my site:
http://localhost:9684/MainPage.aspx?UserID=VABRAEIAUgBBAEUARQBBAFAAUQBBAD0A
It has to check if there is a query string (UserID) and if there is a query string it has to save it in the variable sIngelogdID I'm useing the following code for this:
string sIngelogdID = System.Web.HttpContext.Current.Request.QueryString["UserID"];
However when I look at it in debug mode it says that there are 0 query strings, so it doesn't see UserID as a query string.
This is written in a WCF-RIA-service.
Does anybody have an idea how to achieve this?
Thanks in advance!
EDIT:
The UserID comes from a different Silverlight 4 application. At this application the user logs in after that the login details (the Id of the user that logged in) has to be passed to another Silverlight 4 application. If there is another way (better) way to achieve this, also please let me know.
You may use InitParams instead for sending values.
Firstly capture the querystring from the aspx page which hosted your silverlight application,
In MainPage.aspx.cs
public string GetUserId()
{
return HttpContext.Current.Request.QueryString["UserId"];
}
Now under MainPage.aspx you need to insert code as below under body=> form=> find param and add
<param name="InitParams" value="param1=<%= GetUserId() %>" />
Now capture the param1 in the App.xaml.cs Application_Startup method as
if (e.InitParams.ContainsKey("param1"))
{
userId = e.InitParams["param1"].ToString();
}
Hope this helps
Currently trying to augment the search of an existing ASP.NET site. My background is Java, so if I was writing a server in Java, I could just handle the incoming request as a string and parse it however I wanted, taking out the search terms, etc.
What part of ASP handles that? Where should I be looking for where the incoming string is taken apart to handle the search request? There is a search button which redirects the page to a URL which includes the search parameters. That's where the trail goes cold for me as I need to know where it comes back into the server.
For example, once you've vetted the search term it gets submitted like this:
Response.Redirect("~/shop?" + type + "=" + searchBoxContent);
'type' is the type of search so that could be based on brand or searching within the product description, etc.
The site is already using some type of url rewriting as the url doesn't show up with any .aspx when you do a search. Should I be looking in a config file or a .master.cs file or where to point me in the right direction?
The easiest system for this is ASP.NET MVC which has a built-in Route and parameter handler.
See MSDN for docs.
Example:
{controller}/{action}/{id}
Can redirect to a Controller action:
public ActionResult Find(int id)
{ ... }
If this is not what you want, take a look at this blog article of Scott Guthrie on URL rewriting.
If you have a URL like this:
/shop.aspx?type=abc
then you can use Request.QueryString the get the value of type. This is the syntax:
Request.QueryString["type"]
For example if you want to get the value when /shop.aspx?type=abc is loaded at the first time, then you should add this code in Page_Load method inside the code behind (shop.aspx.cs):
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// assign 'type' query string to typeOfSearch
string typeOfSearch = Request.QueryString["type"];
}
}
Hello to all developers,
I am trying to find some example of Dynamically generate URL(PURL).
I have seen one software which generate personalised URL from MySQL database .
The only thing is that software is using PHP to generate URL and as a .NET developer I dont know about php.
My question is is there a way that I can fetch data from data base and using perticular field i can generate url which is not actually store in my web space..
eeg.
-----database-----
firstname | lastname ....
===========================
xyz abc
pqwert qweoiuy
alfa beta
the URL should be like
http://something.com/somepersonal/xyz_abc.aspx
http://something.com/somepersonal/pqwert_qweoiuy.aspx
http://something.com/somepersonal/alfa_beta.aspx
It is something like personalised page for users or clients.
I have template to use as back page but dont know how to plug and dynamically generate URL..
You're thinking of this a little backward. Generally, one wouldn't do this by generating it directly from the database. You would generally do this by routing the url batch /somepersonal/ to some personalpage control, which would then consider everything after it, like xyz_abc to be an argument. Personalpage would then use that argument to customize its display, be it from the database or wherever.
So to clarify, your URL would look something like:
http://something.com/personal/vish_soni
http://something.com/personal/colonel_gentleman
http://something.com/personal/general_specific
But all of these are being routed to Personalpage, which then uses vish_soni, colonel_gentleman, and general_specific as arguments to query the database or do whatever else it needs to do.
Microsoft has an overview of this pattern and routing in general here.
You can create a controller class and call an action method. For your case, you just need to send parameter and then lookup customer info to prepare the content.
public class HomeController : Controller
{
public ActionResult Me(string id)
{
ViewBag.Message = "Welcome to ASP.NET MVC! "+id;
var contentobj = repository.GetUSerContent(id);
return View("Index",contentobj);
}
}