Subscribe: Custom Server Controls
Added By: Feedage Forager Feedage Grade B rated
Language: English
action method  code  computer  core  data  form  lang  method  mvc  net mvc  net  new  public  request  session  set 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Custom Server Controls

All Forums

All Forums

Last Build Date: Fri, 19 Jan 2018 12:12:09 -0800


Why are there no databases found in my project when publishing MVC app to Azure Cloud?


Hello I've been given an already made publishing profile which I used when publishing my MVC web app to the cloud. But when I have to enter the DB connection string I have been given by my mentor the database connection section of the publishing settings shows that I don't have any databases within the project while I do certainly have a local database.

My question is how can I make the publishing system find the local database so I can enter the connection string to migrate my local DB to the SQL database on Azure Cloud?

Here you can see that it's not showing any databases


This is the action method which I'll use to migrate my local db to the Azure db.

   public IActionResult Migrate()
                    return RedirectToAction("Index");
                catch (Exception e)
                    return RedirectToAction
            ("Foutmelding", new { message = e.Message });

EF code first insert multiple tables


Hello. I create a small application which contain two class :

first Computer.cs

public class Computer {
[Key] [Display(Name = "ID")]
public int idComputer { get; set; }
[Required] [Display(Name = "Computer Name")]
public string ComputerName { get; set; }
[Display(Name = "Manufacturer")]
public string ComputerManufacturer { get; set; }
public virtual ICollection Details { get; set; } }
second Detail.cs

 public class Detail
        public int idDetail { get; set; }
        [Display(Name = "Computer Name")]
        public int idComputer { get; set; }
        [Display(Name = "IP Address")]
        public string IPAddress { get; set; }
      public virtual Computer Computer { get; set; }

and this is Create.chtml

 public class ComputerController : Controller
private InventoryContext db = new InventoryContext();
[HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "ComputerName,ComputerManufacturer")] Computer computer) { try { if (ModelState.IsValid) { if (db.Computers.Any(p => p.ComputerName == computer.ComputerName)) { ModelState.AddModelError("", "Computer name already exists."); } else { db.Computers.Add(computer); db.SaveChanges(); return RedirectToAction("Index"); } } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes."); } return View(computer); }

Please help me to modify ComputerControler to be able to insert data in this two tables same time from one form. Thank you.

Tracking WebAPI per session


I have a webapi and the auth is token based.  The api is using .net core 2.0 and thinking of using idenityserver4 for the token auth.

What we want to do is for each client that authenticates using their clientid/secret is to create lets say a shopping cart which they can use.  There are a few things to consider here.

First each time the client calls api token endpoint they get a cart.  This can happen many times per client.  Second they can terminate each cart by calling a singout endpoint.

My question here is, in a REST service what is the best way to handle this scenario.

Happy to clear up any questions.  Any advice appreciated.

Core 2.0 Loading Session asynchronously



from the MS docs:

The default session provider in ASP.NET Core loads the session record from the underlying IDistributedCache store asynchronously only if the ISession.LoadAsync method is explicitly called before the TryGetValue, Set, or Remove methods. If LoadAsync is not called first, the underlying session record is loaded synchronously, which could potentially impact the ability of the app to scale.

Since I have the SessionExtensions and set/get only one serializable object throughout my app is it enough to just call the LoadAsync at the beginning of the Get and Set extension methods to have the session loading async?

public static class SessionExtensions
    public static void Set(this ISession session, string key, T value)
        session.SetString(key, JsonConvert.SerializeObject(value));

    public static T Get(this ISession session,string key)
        var value = session.GetString(key);
        return value == null ? default(T) : 

Unexpected token < in JSON at position 0



 I have added one new argument (UIDate) to pass to the service in the URL and I got the below error,

Message: "Unexpected token < in JSON at position 0"
stack : "SyntaxError: Unexpected token < in JSON at position 0↵ at parse ()↵ at fn (↵ at k (↵ at XMLHttpRequest. ("


My service call in js

var _url = serviceUrl + '/proxy.svc/availability?lineOfServiceId=' + lineOfServiceId + '&resourceId=' + resourceId + '&UIDate=' + UIDate + '';

tcm.get(_url, {
success: function (msg) {
var result = msg.availabilityResult;
if (result.Data != null && result.Data.length > 0) {
var SlotsAvailable = [];
SlotsAvailable.push({ 'avSlots': result.Data, 'rId': resourceId, 'LosId': lineOfServiceId });
error: function (request, status, error) {
var SlotsAvailable = [];
SlotsAvailable.push({ 'avSlots': '', 'rId': resourceId, 'LosId': lineOfServiceId });
return def;

 Please help me to fix the issue.


FtpWebRequest in web form


ftp connection has error {"The requested URI is invalid for this FTP command."}

Error occurs on line: FtpWebResponse response = (FtpWebResponse)request.GetResponse();

My code is based on this web site example:

Trying to connect to FTP server, NOT SFTP. My username and password and host works in FileZilla and not my code. What do I need to do to get my code to work?

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(sftpHost);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = true;
request.UsePassive = false;
request.UseBinary = false;
request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

using (FileStream writer = new FileStream(strFilePathAndName, FileMode.Create))

long length = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[2048];

readCount = responseStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
writer.Write(buffer, 0, readCount);
readCount = responseStream.Read(buffer, 0, bufferSize);


VS Team Services - website pathway in solution file causing build error



This is probably something simple that I am doing wrong as I am new to VSTS. 

I have uploaded my existing .NET website project to VSTS and when I run a build definition in VSTS, I get an error in the solution file.

I can see what the problem is....the solution file has the pathway of the project on my PC in it...which is stored in inetpub/wwwroot/VSProjects on my PC.

Is there something simple I am missing to avoid this?

Thanks for any help...

Here are the build solution log errors -

2018-01-19T16:34:14.3619604Z   C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /PropertyRegister -p ..\..\..\..\..\..\inetpub\wwwroot\VSProjects\PropertyRegister\ -u -f PrecompiledWeb\PropertyRegister\
2018-01-19T16:34:16.1411730Z ##[error]ASPNETCOMPILER(0,0): Error 1003: The directory 'd:\inetpub\wwwroot\VSProjects\PropertyRegister\' doesn't exist.
2018-01-19T16:34:16.1419278Z ASPNETCOMPILER : error 1003: The directory 'd:\inetpub\wwwroot\VSProjects\PropertyRegister\' doesn't exist. [d:\a\3\s\PropertyRegister\PropertyRegister.metaproj]
2018-01-19T16:34:16.1806460Z Done Building Project "d:\a\3\s\PropertyRegister\PropertyRegister.metaproj" (default targets) -- FAILED.
2018-01-19T16:34:16.1818301Z Done Building Project "d:\a\3\s\PropertyRegister\PropertyRegister.sln" (default targets) -- FAILED.
2018-01-19T16:34:16.1837587Z Build FAILED.
2018-01-19T16:34:16.1882800Z "d:\a\3\s\PropertyRegister\PropertyRegister.sln" (default target) (1) ->
2018-01-19T16:34:16.1884216Z (ValidateProjects target) ->
2018-01-19T16:34:16.1885795Z   d:\a\3\s\PropertyRegister\PropertyRegister.sln.metaproj : warning MSB4121: The project configuration for project "PropertyRegister" was not specified in the solution file for the solution configuration "Release|Any CPU". [d:\a\3\s\PropertyRegister\PropertyRegister.sln]

Core 2 Support



SignalR for Core 2 is currently in Alpha. Is there any roadmap or target dates for it to progress to Beta and Production?



IIS Express doesn't recognize and .html changes


When debugging an ASP.NET MVC (SPA) application, I used to be able to make changes to the files and .html files that were served by IIS Developer Express and just simply refresh the browser to see the changes. For a while now, it seems that IIS Developer Express has not recognized the changes to the file system, and doesn't show a different "Last-Modified" date when the browser performs GET requests for the and .html files. So, in most cases, the browser uses the cached version of the and .html files because it thinks the files haven't changed. I have gotten around this for the most part by referencing the and .html files with an extra query parameter (ex: /scripts/myscript?2342344322234) so that the browser always sees it is a new (un-cached) request. However, this isn't very efficient for a number of reasons, including the fact that Visual Studio doesn't recognize the file in the editor, so breakpoints don't get hit.

What do I need to do to get VS (or IIS Express) to recognize changes and respond appropriately with the correct "Last-Modified" date?

response sending back NullReferenceException


I'm having an issue returning data from a web API call.
The web API function looks like this:
        public async Task GetProjects()
            var projects = _projectService.GetProjects().ToList();
            return Request.CreateResponse(HttpStatusCode.OK, projects, System.Net.Http.Formatting.JsonMediaTypeFormatter.DefaultMediaType);
The problem is that the results that return say there was a NullReferenceException. I know that the list of projects that's returned is not null or empty. I think it has something to do with the json formatter.
Any suggestions?

Need some help with api usage


Is there some document or eeading material that can explain why api and rest api was developed. Why were they required and what limitations were faced prior to them.
I would like to understand more


WebApplication hangs while reading data from large database


I have a web application which reads data from DB and displays it on UI.

Generally system need 8-9 minutes time to get data from DB, mean while if i click on any other menu---> system takes lot of time to respond.

How do we fix this issue?

ASP.NET MVC Core 2 - Which one to choose "MVC Approach" or Razor Pages


Hi All,

I am currently trying ASP.NET MVC Core 2. Today I come across the concept of Razor Pages "roughly" similar to old aspx and code behind file in web forms. Now the question is which approach to use MVC or Razor pages from now


Apply Padding To Left And Right


I know how to apply padding to a div tag, but is there a way I can apply padding to the entire web form on the left and right side?

View Component does not POST/GET to action method


I have a viewcomponent in my _Layout Page as follows:

That should send the form to an action method named: "RedirectToLanguage" if I use Post the form never submit and I get 404 but if the method is Get it goes to Index action method and tries to load it and its layout page again. the work of the "RedirectToLanguage" is to request the index action method with a new lang parameter, but when I place a debug mark to this action method it never executes. my take is the view component's form does not send to its target, "RedirectToLanguage". Is it related to viewcomponents or it is my own mistake?  I had  no problems with child actions in such scenarios. and in general is it possible to post/get a form from viewcomponent's view to an action method?



This is the RedirectToLanguage action method:

        public ViewResult Index(string lang)
            ViewBag.Lang = lang;
            return View();            

        public IActionResult RedirectToLanguage(string lang)
            return RedirectToAction("Index", "Home", new { lang = lang });

web form 2010 want intellisense when using jquery


I am working with a 2010 web form application that uses jquery. In the original version of the code there were vsdoc files associated with the application so that intellisense worked in Visual Studio.

Now I am in the process of changing the application to use the current version of jquery. When I go to the website to download the latest version of the jquery core library, there is not an option to download a vsdoc.

Thus can you tell me what I can do in visual studio 2010 to have intellisense work when I am accessing the current version of jquery?

How insert multiple names on a single form into the same field in a database



I need to modify a C# page. What is the best way to insert multiple names on a single form into the same field in a database? Is it possible using Text field? Thanks.

EX: On the Form

Name: Joe
Phone: 1000000000

Name: Greg
Phone: 2000000000

Name: Ann
Phone: 3000000000





Name      Phone
Joe          1000000000
Greg       2000000000
Ann        3000000000

What is the advantageous using mvc core rather than mvc



Please anybody can let me know what is diffrence between the mvc core  and  just mv. What would you suggest for a new project either to go with mvc or core

Please can you let me know




Can someone help me with my code? I tried to solve it for hours but just couldnt get it right!

protected void BtnEdit_Click(object sender, EventArgs e)
            string sql = @"UPDATE Meeting SET date = {1},
                                            room_id = {2}
                                            attendees_pax = '{3}',
                                            start_time = '{4}',
                                            end_time = '{5}',
                                            where meeting_id = {0}";

            int rowsAffected = DBUtl.ExecSQL(sql,

            if (rowsAffected == 1)
                LtlMsg.Text = "Error";

I kept getting 2 errors;


An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code. Additional information: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

2. An exception of type 'System.NullReferenceException' occurred in  System.dll but was not handled in user code Additional information: Object reference not set to an instance of an object.

How to modify this code used by PHP into code use by ASP.Net ?


The following code is from example page of a js and it is post method for PHP

(1) How to modify to be used in ASP.Net ?

Is it I only need to change .php into .aspx ?

(2) What is the code to get the "newValue" ? Is it "GET" ?
Any sample to get this value into Label1.text on the script.aspx ?


$('#editable td').on('change', function(evt, newValue) {
	$.post( "script.php", { value: newValue })
		.done(function( data ) {
    			alert( "Data Loaded: " + data );