Menu
  • HOME
  • TAGS

Server side session in asp.net

Tag: asp.net,web-services,session

I want to set one value in server side session in client side and need to access that session in web service, so i tried below

In client side :

//Set the server side session like below  
 var vr_="demo.png";     
'<%Session["path"] = "' + vr_ + '"; %>';

//In alert,checked the server side session value like below
 alert('<%=Session["path"] %>');

the value getting in alert is fine and i called the web service but when try to access the session in web service i am getting the following as session value

' + vr_ + ' not the original value "demo.png"

Please find the source code below,

In Javascript :

  var vr_="G:\\13-06-15-demo\\app1\\uploads\\demo.png"

In Jquery ajax request, i called the webservice like below

 $.ajax({
        url: "../webservice/email.asmx/senmail",
        data: "{'tomail': '" + tomail + "','subject': '" + subject + "','message': '" + message + "','attachment': '" + vr_+ "'}",           
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",

In web service, the method is like below

 public bool senmail(string toMailId, string subject, string message,string attachment)
    {

Best How To :

You've got a quotes problem, fix it like this:

<% Session["path"] = "'" + vr_ + "'"; %>

EDIT 1:
Javascript and ASP.NET are not the same, so you cannot access the variables, so you can't do it on the client side. You must send something to the server like a POST request using Javascript or easier using jQuery.

Here are some resources:

Using AJAX and Javascript:
http://www.w3schools.com/php/php_forms.asp http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

jQuery AJAX: http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.post/

EDIT 2:
The answer was to create a normal javascript object/array and then convert it to JSON using JSON.stringify(), like seen in this example: Jquery Ajax Posting json to webservice.

JSON.stringify(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

.NET wep api won't accept %2E or . in api request uri

c#,jquery,asp.net,ajax,json

Have a look at this answer MVC4 project - cannot have dot in parameter value? Try changing the Web.Config file <system.web> <httpRuntime relaxedUrlToFileSystemMapping="true" /> </system.web> ...

Make uneven table layout

html,asp.net

You can solve this using the attribute colspan on the td tag: <table border = "1"> <tr> <td colspan="2"> Do you love peanuts? This is a very important question. </td> </tr> <tr> <td> Yes, I do. </td> <td> No, I don't. </td> </tr> </table> Check this link ...

error: cannot find symbol class AsyncCallWS Android

java,android,web-services

On the link you post, I see a class like below. Create this class in your project before using it. private class AsyncCallWS extends AsyncTask<String, Void, Void> { @Override protected Void doInBackground(String... params) { Log.i(TAG, "doInBackground"); getFahrenheit(celcius); return null; } @Override protected void onPostExecute(Void result) { Log.i(TAG, "onPostExecute"); tv.setText(fahren +...

Third-party security providers like Google, Twitter etc. in ASP.Net

asp.net,authentication

No, you cannot enter any string. You will need to register with each provider to get the parameters that you need. See http://www.asp.net/web-api/overview/security/external-authentication-services for instructions on how to do this....

why does the compiler complain about missing ctor of WebSocketHandler?

asp.net

protected member is accessible by derived class instances and there's nothing special about it. Nothing special in the class itself, either @ WebSocketHandler.cs. It just mens you need to pass in a nullable type, it does not mean it can't get any arguments. int? maxIncomingMessageSize = 0; var socket =...

Access manager information from Active Directory

c#,asp.net,active-directory

try this: var loginName = @"loginNameOfInterestedUser"; var ldap = new DirectoryEntry("LDAP://domain.something.com"); var search = new DirectorySearcher(ldap) { Filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" + loginName + "))" }; var result = search.FindOne(); if (result == null) return; var fullQuery = result.Path; var user = new DirectoryEntry(fullQuery); DirectoryEntry manager; if (user.Properties.PropertyNames.OfType<string>().Contains("manager")) { var managerPath...

Can't save json data to variable (or cache) with angularjs $http.get

json,angularjs,web-services,rest

$http.get is asynchronous. When cache.get or return result are executed, HTTP request has not completed yet. How are you going to use that data? Display in UI? E.g. try the following: // Some View <div>{{myData}}</div> // Controller app.controller('MyController', function ($scope) { $http.get('yoururl').success(function (data) { $scope.myData = data; }); }); You...

Azure Mobile Services: migrate to non-Azure Windows Server

asp.net,azure,azure-mobile-services

It is entirely possible to move the .NET runtime - This is just an ASP.NET Web API site, and it can be hosted anywhere that you might run ASP.NET. However, some features such as the login functionality will not be available. For the Node.JS runtime, the actual process running the...

How to format label in ASP.net chart control

c#,asp.net,asp.net-mvc,c#-4.0,reporting-services

Use formatting: DateTime.Now.ToString("dddd, dd-MM-yy"); Output: Montag, 15-06-15 //Written day of week in your local culture. To edit the axis labeling, you can do it in your code-behind file: Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dddd, dd-MM-yy"; Or in your markup: <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisX Title="Date" IsLabelAutoFit="True" TitleForeColor="#ff0000"> <LabelStyle Format="dddd, dd-MM-yy" /> <MajorGrid Enabled ="False"...

add BR between text in dynamically created control

c#,asp.net

You need to use InnerHtml property HtmlGenericControl li = new HtmlGenericControl("li"); li.ID = "liQuestions" + recordcount.ToString(); li.Attributes.Add("role", "Presentation"); ULRouting.Controls.Add(li); HtmlGenericControl anchor = new HtmlGenericControl("a"); li.Attributes.Add("myCustomIDAtribute", recordcount.ToString()); anchor.InnerHtml = "Test <br/> 12345"; li.Controls.Add(anchor); Or, like this: anchor.Controls.Add(new LiteralControl("Test")); //or new Literal("Test"); anchor.Controls.Add(new HtmlGenericControl("br"));...

Is communication via web services standardized among JavaScript on different browsers?

javascript,web-services

If this code works in Chrome, can I assume that it will also work in other major browsers assuming you will be creating a httpRequest object and the appropriate fallback for what ever browsers you are using, then you can presume that it will work across browsers, providing the...

How do ASP.NET Web APIs work once built with MSBUILD?

c#,asp.net,msbuild

The WebApi is a web project and on compiling it creates a dll. It is not a class library or a nuget package to consume and use it. I have practically implemented this in a real world application and below are my thoughts for your understanding. Your question is Once...

Multiple Posted Types asp.net 5 MVC 6 API

c#,asp.net,asp.net-mvc,asp.net-5,asp.net-mvc-6

The best way is to create a composite wrapper: public class Wrapper { public ModelA A { get; set; } public ModelB B { get; set; } } Put Wrapper in the parameter list and mark that [FromBody]. You can't use that attribute more than once because all of the...

Why is my View not displaying value of ViewBag?

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor

ViewBag is used when returning a view, not when redirecting to another action. Basically it doesn't persist across separate requests. Try using TempData instead: TempData["Tag"] = post.SelectedTag.ToString(); and in the view: <p><strong>Tag: @TempData["Tag"]</strong></p> ...

Database object with different data

sql,asp.net,asp.net-mvc,database,entity-framework-6

Ideally what you want is a many-to-many relationship between your Shop and Product entities: public class Shop { public int ShopId {get; set;} public virtual ICollection<ShopProduct> ShopProducts {get; set;} } public class Product { public int ProductId {get; set;} public string Name {get; set;} public virtual ICollection<ShopProduct> ShopProducts {get; set;}...

Server side session in asp.net

asp.net,web-services,session

You've got a quotes problem, fix it like this: <% Session["path"] = "'" + vr_ + "'"; %> EDIT 1: Javascript and ASP.NET are not the same, so you cannot access the variables, so you can't do it on the client side. You must send something to the server like...

ASP.NET httpHandlers & handlers

asp.net,asp.net-mvc

The system.webServer section in the Web.config file specifies settings for IIS 7.0 that are applied to the Web application. The system.WebServer is a child of the configuration section. For more information, see IIS 7.0: system.webServer Section Group (IIS Settings Schema). and <system.web> specifies the root element for the ASP.NET configuration...

CommandName = Insert in EditTemplate of ASP.NET ListView throws “Insert can only be called on an insert item”

c#,asp.net,listview

The error is self explanatory. Take a look at this: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.insertitemtemplate(v=vs.110).aspx So you can do either of these things. Create an InsertItemplate and insert using the ItemInserted event of the listview Change the CommandName to CommandName="InsertData" and catch that event on the ItemCommand ...

Show/hide tinymce with radio buttons

c#,asp.net,asp.net-mvc,tinymce

Your missing an @symbol for the id attribute: Modify your script as well like this: ***EDIT some thing seems off about the radio buttons only one should be checked and they should have the same name ** you can use the # to denote and ID in Jquery by the...

How to make a website work only with https [duplicate]

asp.net,ssl,https

Sure, assuming you are using IIS to host your site, open IIS Manager and select your web site and then binding on the right: make sure you only have a binding for https not for http. This way IIS will only send https traffic to that web site. Edit: What...

Can I uniquely identify 2 check boxes so that I can add a different image to each?

html,css,asp.net,checkbox

Here is an example of what I meant: (Oh and, forgive the images please :) ) #field1,#field2{ display:none; } #field1 + label { padding:40px; padding-left:100px; background:url(http://www.clker.com/cliparts/M/F/B/9/z/O/nxt-checkbox-unchecked-md.png) no-repeat left center; background-size: 80px 80px; } #field1:checked + label { background:url(http://www.clker.com/cliparts/B/2/v/i/n/T/tick-check-box-md.png) no-repeat left center; background-size: 80px 80px; } #field2 + label { padding:40px;...

System.net.http.formatting causing issues with Newtonsoft.json

c#,asp.net,asp.net-mvc,json.net

Does the assemblyBinding tag have proper xmlns schema? Check if the issue you are encountering is same as Assembly binding redirect does not work

Cant delete in database because of constraints

c#,sql,asp.net,oracle

Best way to do it is by using a stored proceed rather than a sql statement in C# code. You are getting error because the referenced records are still present in referenced table and are using cmd.ExecuteReader(); rather than cmd.ExecuteNonQuery();. So you need to delete records for DBS2_MOVIE WHERE MOVIE_ID...

Convert Double from String

asp.net,vb.net,visual-studio-2012,converter

The result isn't wrong, it only has lower precision than you expected. Floating point numbers have a limited precision by design, and you simply can't expect to get a result that is more precise than its limit. You can use a Decimal to get higher precision. In this case it...

Retrieve data from one table and insert into another table

sql,asp.net,sql-server

INSERT INTO tbl2 ( Name ,parentId ) SELECT DISTINCT manager ,0 FROM tbl1 WHERE manager NOT IN ( SELECT employee FROM tbl1 ) INSERT INTO tbl2 SELECT DISTINCT employee ,0 FROM tbl1 UPDATE tbl2 SET parentid = parent.id FROM tbl2 INNER JOIN tbl1 ON tbl2.Name = tbl1.employee INNER JOIN tbl2...

How IE setting affect authorization

asp.net,iis

If you set "Enable Integrated Windows Authentication" (which is the default), and the server requires integrated Windows authentication, then the user will be authenticated silently using current default credentials, if possible. If you disable Integrated Windows Authentication, the user will be prompted to supply credentials. See this KB article for...

Android AsyncTask with JSON Parsing error

java,android,json,web-services,wcf

It seems you havn't use your JSONArray object JSONArray mainfoodlist = null; tipshealth = json.getJSONArray(TAG_RESPONSE); // looping through All RESPONSE for (int i = 0; i < tipshealth.length(); i++) { JSONObject jsonobj = tipshealth.getJSONObject(i); tipHealth = jsonobj.getString(KEY_HEALTHTIPS); listhealthtips.add(tipshealth.getJSONObject(i).getString("tips")); } ...

Select @field From table as parameter

asp.net,sql-server,parameter-passing

If doing it from codebehind works then you can do something like sdsOrderErrors.SelectCommand = string.Format("SELECT {0} AS fld FROM [a_table]", colName); (OR) Have a stored procedure to accept a parameter and perform a dynamic query to achieve the same like create procedure usp_testSelect(@colname varchar(30)) as begin declare @sql varchar(200); set...

Trigger a js function with parameter from code behind

c#,jquery,asp.net,scriptmanager,registerstartupscript

All you need to do is add a semi-colon to the end of your String.Format call. ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptManager1", String.Format(@"ShowHideMessageBlock('{0}');", @"#successMsg"), true); ...

RequiredFieldValidator not working in my ASp site

c#,css,asp.net,twitter-bootstrap

You just miss a little thing i.e. to assign a Validation Group to your buttons and your RequiredFieldValidators. Your code should be: <div class="container"> <h2>Registration</h2> <p>Please fill out the forms to complete your registration.</p> <form role="form"> <div class="form-group"> <label for="username">Name:</label> <asp:TextBox runat="server" ID="UserName" CssClass="form-control" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"...

Cannot start Website in IIS - W3SVC running

asp.net,iis

First verify that the World Wide Web Publishing Service is installed and not disabled. [Source:MSDN] Right-click My Computer on the desktop, and then click Manage. Expand the Services and Applications node, and then click the Services node. In the right pane, locate the World Wide Web Publishing Service. If the...

onSuccess and onFailure doesn't get fired

javascript,c#,asp.net,webmethod,pagemethods

You PageMethod is looking like this PageMethods.LoginUser(onSuccess, onFailure, email, pass); And when you call it, it looks like this PageMethods.LoginUser(email, pass); Your arguments should be in the same order as the method. PageMethods.LoginUser(email, pass, onSuccess, onFailure); ...

Sending LIst via ajax to complex model

javascript,c#,asp.net,ajax

You don't need to JSON.stringify the recipients. "recipients": JSON.stringify("[{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}]") Remove JSON.stringify form here and it should work. var postData = { "workplaceGiverId": $(".wpgDropdownList").val(), "fromMemberId": $(".wpgFromMemberDropdownList").val(), "toMemberId": $(".wpgToMemberDropdownList").val(), "voucherExpiryDate": $("#expiryDatePicker").val(), "recipients": [{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}] }; ...

Asp.Net Identity find users not in role

asp.net,linq,entity-framework,asp.net-identity

In c# you can get all users that are not in a certain role like this: var role = context.Roles.SingleOrDefault(m => m.Name == "role"); var usersNotInRole = context.Users.Where(m => m.Roles.All(r => r.RoleId != role.Id)); ...

Creating a viewmodel on an existing project

c#,asp.net,asp.net-mvc

You are using a namespace, your full type name is Project.ViewModel.ViewModel (namespace is Project.ViewModel and class name is ViewModel) so use this using instead: @model Project.ViewModel.ViewModel ...

SQL Server / C# : Filter for System.Date - results only entries at 00:00:00

c#,asp.net,sql-server,date,gridview-sorting

What happens if you change all of the filters to use 'LIKE': if (DropDownList1.SelectedValue.ToString().Equals("Start")) { FilterExpression = string.Format("Start LIKE '{0}%'", TextBox1.Text); } Then, you're not matching against an exact date (at midnight), but matching any date-times which start with that date. Update Or perhaps you could try this... if (DropDownList1.SelectedValue.ToString().Equals("Start"))...

Difference between application and module pipelines in Nancy?

c#,asp.net,nancy

The module- and application pipelines are explained in detail in the wiki. It's basically hooks which are executed before and after route execution on a global (application pipelines) and per-module basis. Here's an example: If a route is resolved to a module called FooModule, the pipelines will be invoked as...

Callback on client does not get triggered with SignalR

javascript,c#,asp.net,signalr

It looks like you are missing client in: $hub.client.onRecieveNotification = function (message) { $("#message").append($("<li></li>", { text: message })); } ...

Unable to find the auto created Database

c#,asp.net,asp.net-mvc,entity-framework

If you don't specify a database name then the connection will use the default database for the user, in this case it's integrated security so it's your Windows login. As you likely have full system admin on the server the default database will be master so you will find all...

Save SOAP UI mock requests to a file

web-services,soap,request,soapui

If you want to save in a file all request that your Mock service recieve, simply do the follow. In your mock service open the onRequest script tab as in the follow image (this script executes each time that your service receives a request): And add the follow groovy script...

Problems With FOR XML AUTO

sql,asp.net,sql-server,subquery,sqlxml

Change XML PATH('') to XML PATH('tag')

Catch concurrency exception in EF6 to change message to be more user friendly

c#,asp.net,.net,entity-framework,entity-framework-6

You are executing an asynchronous method. This means that any exceptions will be thrown when you call await on the returned task or when you try to retrieve the results using await myTask; You never do so, which means that the exception is thrown and caught higher up your call...

deployment of a site asp.net and iis

c#,asp.net,iis

There are several domain providers like: godaddy, name etc you can use to buy a domain name. These providers also provide you steps to map the domain name to your website. Check out this link for example. This link explains domain name configuration in details.

Event on dynamically created checkbox asp.net

c#,jquery,asp.net,table,checkbox

you can try this code List<CheckBox> lstChckBox; protected void Page_Load(object sender, EventArgs e) { // you can create controls programaticaly or html page, doesnt important //only you should know controls ID and all controls share same checked event CheckBox chc1 = new CheckBox(); chc1.CheckedChanged += new EventHandler(chck_CheckedChanged); CheckBox chc2 =...

WCF service architecture query

asp.net,architecture,wcfserviceclient

As long as you are able to use the exact same contract for all the versions the web application does not need to know which version of the WCF service it is accessing. In the configuration of the web application, you specify the URL and the contract. However, besides the...

check if file is image

c#,asp.net,asp.net-mvc

You can't do this: string.Contains(string array) Instead you have to rewrite that line of code to this: if (file == null || formats.Any(f => file.Contains(f))) And this can be shortened down to: if (file == null || formats.Any(file.Contains)) ...

Consuming and exposing webservices in one project (.NET)

.net,web-services,rest,soap

If you are trying to enrich the data from one source and combine that with information from another source, I think this is a decent solution. I think it is better to have one single point to talk to (your REST service), than to have two in your application and...

asp.net background in 3 pieces to be stationary

html,css,asp.net

I would use a separate div and use fixed positioning on it. Example <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Layout Example</title> <link rel="stylesheet" type="text/css" href="./Layout Example_files/style.css"> <style type="text/css"> .fixed-background{ background: url( "images/SoapBubbles.jpg" ) no-repeat fixed top center; position:fixed; z-index:-1; top:0; right:0; left:0; bottom:0; } </style> </head> <body> <div...

Gridview items not populating correctly

asp.net,vb.net

Try this vb code behind, then comment out my test Private Sub BindGrid() Dim dt_SQL_Results As New DataTable '' Commenting out to use test data as I have no access to your database 'Dim da As SqlClient.SqlDataAdapter 'Dim strSQL2 As String 'Dim Response As String = "" 'strSQL2 = "SELECT...