how to get the value from address bar entered by client? [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I don't know how to put the title but i will try to explain it the requirement here.
Normally user entered an URL in address bar in browser, for example www.example.com, then click a link and redirect to another page www.example.com/test.aspx. Alternatively, user also can just enter/type www.example.com/test.aspx from address bar if they know the full path.
So, i required to write a code where user can type an URL in address bar, for example www.example.com/test.aspx?usr="www.test.com". (note: with addition usr="www.test.com")
The "usr="www.test.com" after www.example.com/test.aspx? contain a value that stored in database.
So, when the user type www.example.com/test.aspx?usr="www.test.com" it will search the database for matching www.test.com and do some process if found.
How can i achieve this.

You have to use Request.QueryString to get value any param passed to the page.
The result, stored in a page variable, can be used to retrieve the needed data.
string usr = Request.QueryString["usr"];

You can get the values in url after ? from HttpContext using
string url = HttpContext.Current.Request["usr"];

If the value is being passed through in the query string (the part after the '?'), you can just check for it using the Request object.
C#
string url = HttpContext.Current.Request["usr"];
// Then perform your search based on the value in URL.
Note: You can also use string url = HttpContext.Current.Request.QueryString["usr"]; if you want to ensure that your value of usr is only from the query string and not a POST or COOKIE. See here for further info.

Related

Expected 1 Actual 0 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
i am developing a Spring .net Application.
I have a Login Page with fields - LoginID Password
On Login-There is a form to be filled by the candidate
so after Login I check if the candidate has already filled form then the values are fetched from the database and shown in the form fields.
Now When the Candidate hasn't filled the form the database null rows for it and hence it gives me the above error..please tell me how should I resolve this error.
I tried checking if the obj is null but it does not go to to the next line to check of the obj is NULL it immediately throws the above mentioned exception
IT GIVES ERROR IN LINE 6 OF THE PAGE_LOAD FUNCTION
EXCEPTION:EmptyResultDataAccessException was caught
Incorrect Resultsize Expected 1 Actual 0
As I said above, I've never worked with Spring.NET, but taking a look at the documentation I believe you may be using the wrong method of the AdoTemplate class. QueryForObject, per the documentation, will `Execute a query mapping the result set to an object using a IRowMapper. Exception is thrown if the query does not return exactly one object.'
In your example, if the user is not registered, they won't be in the database, so 0 results will be returned. Hence the error Incorrect Resultsize Expected 1 Actual 0.
Try using the QueryWithRowMapper method, as it is (again, per the documentation) one of the methods for Mapping result sets to objects:
return (CandidateSession)template.QueryWithRowMapper(CommandType.StoredProcedure, "spGetCandidateSession", candidateMapper, parameters);
If the cast to CandidateSession does not fail, I would expect a null object to be returned.
Again, I've never worked in Spring.NET, so this is based on a fairly cursory reading of the documentation. Hopefully it will at least get you going down the right path.

How to get web application Database Status in asp.net? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to show one detail_report page of my web application which is hosted on server.
We have used asp.net to create that application.
I have following list to show on detail_page
Host Name
Host Date/Time
Database Status
Build Version
Build Timestamp
I'm really trying to get Database Status using Ping but unable to do that.
anyone can help me I need to use asp.net + C#
Why do you need to ping database in order to get status of database?
Just handling the sql connection exception in your application will be enough to show the related information on server status. In addition to the exception handling, when your DB is down, you may also use connection string information to display the DB name, and other information from resource files like web.config.
However, i hope you don't have plans to display username and password of the connection string to your users :)
You may try doing something like this. Hope this helps.
public void displayDBDetails()
{
SqlConnection sqlConn = new SqlConnection(string yourConnectionString);
sqlConn.Open();
string dbName = sqlConn.Database.ToString();
string dbStatus = sqlConn.State.ToString();
string dbServerVersion = sqlConn.ServerVersion.ToString();
etc.....
}

variable name with a white space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to have a variable name with a white space.
Am passing this collection to a gridview and i need the title to have a white space instead of an underscore
var registrationReport = (from r in BankMedEntity.Customers
select new {r.Id,Customer Type = r.CustomerType_Id });
Any idea on how i can accomplish that?
I need to have the title as "Customer Type" instead of "CustomerType_Id"
You cannot, c# does not allow spaces in variable names. They would be considered different words and the compiler will go "Ahh...What do you mean?"
Turn this to false
AutoGenerateColumns="True"
And add your own Bound columns to the Gridview. You will be able to give the columns whatever names you want
Unfortunately that is impossible; the compiler has no way of figuring out that the two separate words are actually part of the same variable name.
No space is allowed in variable name.
If you want the title of the gridview with no underscore, you should edit the girdview definition in .aspx file.

protecting files for download just for user that has credit in his/her acount? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
i wanna creat a website for downloading some files (pdf,word,xls, such as these files), each file has pice for example a.pdf is 10$ and b.pdf id 20$. For example usern "x" has 12$, how can i prevent this user for download file b.pdf ? Please giv me suggestions. You know i know that i can have membership system that can hqve roles for accessing folders but how about files ? Or you think i dont need to register users they can pay online price for each file, for example you select a.pdf and you will connect to paypal or others and you`ll pay, if you pay the link will be shown but how about if the user copy the link and send it to him/her friends ? Thank you
You should put the files off of the web root (so that they cannot be accessed by URL).
Then, you can write an ASHX file or MVC action that takes a filename, checks whether the logged-in user is allowed to access it, and, if so, returns the file by calling Response.TransmitFile.
For this I would use a generic handler, like SLaks suggests: Add New -> Generic Handler (.ashx) file. Then in the handler class:
public class CustomImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Get file name from query string and check balance for that file extension... read the file into aStream
context.Response.Clear();
context.Response.ContentType = "image/...";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", GetTheFileName()));
context.Response.BinaryWrite(aStream.ToArray());
}
}
Then the image hyperlinks are:
http://yourdomain.path/../CustomImageHandler.ashx?filename=file1.pdf
You could have a page that accepts the file id as a GET parameter, and have the code behind check against their balance.
i think i got it when the transaction completed successfullu it will return true and i can check if the returned value is true the file cqn be download with the current user. Thanks for your help :x

C# asp.net parameters cast to a page [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
if you please help me out i am trying to pass 3 different parameters in a page but i am new in asp.net C# and i don't know the correct syntax if you please help me out
;
For one parameter like this it works:
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue);
how can i write it for 3 parameters like this don't seem to work?
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue+"&cr="+ListBox3.SelectedValue+"&p="+ListBox1.SelectedValue)
thanks in advance
You forgot a + in your string concatenations after the cr parameter. This being said a far safer and better approach which ensures that your parameters are properly encoded is the following:
var parameters = HttpUtility.ParseQueryString(string.Empty);
parameters["q"] = ListBox1.SelectedValue;
parameters["cr"] = ListBox3.SelectedValue;
parameters["p"] = ListBox1.SelectedValue;
var url = string.Format("~/WebPage2.aspx?{0}", parameters.ToString());
Response.Redirect(url);
And of course if you are using ASP.NET MVC (as you've tagged your question with it) you would use:
return RedirectToAction("SomeAction", new {
q = ListBox1.SelectedValue,
cr = ListBox3.SelectedValue,
p = ListBox1.SelectedValue
});
I very sincerely hope that if you are using ASP.NET MVC then ListBox1 and ListBox2 is not what I think it is.
Here's what I typically do (assuming a constant number of parameters for each URL):
string url = "~/WebPage2.aspx?q={q}&cr={cr}&p={p}";
url = url.Replace("{q}", ListBox1.SelectedValue)
.Replace("{cr}", ListBox2.SelectedValue)
.Replace("{q}", ListBox3.SelectedValue);
Response.Redirect(url);
I have not tested it, but this may be relatively inefficient. The reason I do it this way is so I know exactly what the URL pattern looks like and which parameters are used.
It's a trade-off to be sure, and am curious to see other peoples' feedback.

Categories