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
Related
I have a dot net mvc application and want to perform a database check about whether the user has accepted the terms and conditions or not at the start of the application and redirect the user to the terms and condition page based on the result. Where should I place the code snippet ?
Till now I tried to redirect from global.asax file to a route and then calling a method from the control to perform the check But however it is giving the Response does not exist in the currrent context.
I tried this piece of code :
Response.RedirectToRoute("Terms",false);
I am very new to this so please excuse if the question really dumb.
Place your code snippet in the ActionResult of the Index Page(which is the default page that loads when the application starts.) in the HomeController.
Get your user from either a session and check against the user in your database to see if they have read the terms and conditions.
It will look something like this
public ActionResult Index()
{
var user = Session["loggedUser"] as User;
user = db.Users.Find(user.id);
if(!user.hasReadTerms)
{
return Redirect("/Terms");
}else
{
//continue
}
}
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
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);
}
}
I am coding an application and I would like to give the admin a way to reset a password. The closest I have come to this is the following:
public abstract string ResetPassword(string username, string answer);
But this requires I know the answer.
With the .NET MembershipProvider how can I simply reset a password to something else? The only way I can think to do this is to delete the user and recreate.
Do you implement your custom MembershipProvider? if so set RequiresQuestionAndAnswer to false and you will not need to provide the answer in ResetPassword.
see:
http://www.asp.net/security/tutorials/recovering-and-changing-passwords-cs
It's pretty easy to add the password recovery feature to an MVC project. I've got a blog post on my site where I detail the code that you need to add to your controller, model, and views:
http://hectorcorrea.com/Blog/Password-Recovery-in-an-ASP.NET-MVC-Project
I wasn't able to do what you desire using only Membership... I had to use System.DirectoryServices.
Assuming you can get a Directory Entry, try this:
public void SetPassword( DirectoryEntry AdEntry, string userPassword )
{
ADEntry.Invoke( "SetPassword", new object[] { userPassword } );
ADEntry.CommitChanges();
}
If you need more help look here :
Howto: (Almost) Everything In Active Directory via C#